package com.vr.xuecheng.orders.controller;

import com.vr.xuecheng.orders.dto.AddOrderDTO;
import com.vr.xuecheng.orders.service.IOrdersService;
import com.vr.xuecheng.orders.vo.PayRecordVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author hzh
 * @date 2025/04/06
 * 订单支付控制器
 */
@Tag(name = "订单支付控制器")
@Log4j2
@Controller
@RequiredArgsConstructor
public class OrderController {
    private final IOrdersService ordersService;
    @Operation(summary = "生成支付二维码")
    @PostMapping("/generatepaycode")
    @ResponseBody
    public PayRecordVO generatePayCode(@RequestBody AddOrderDTO addOrderDto) {
        return ordersService.generatePayCode(addOrderDto);
    }
    @Operation(summary = "扫码下单支付")
    @GetMapping(value = "/requestpay")
    @ResponseBody
    public void requestPay(@RequestParam("payNo") String payNo, HttpServletResponse httpResponse) {
       ordersService.pay(payNo,httpResponse);
    }
    @Operation(summary = "查询支付结果")
    @GetMapping("/payresult")
    public PayRecordVO payResult(String payNo) {
        return null;
    }
    @Operation(summary = "支付通知")
    @PostMapping(value = "/pay/notify")
    public void receiveNotify(HttpServletRequest request, HttpServletResponse out) {
        System.out.println("收到支付结果通知");
        ordersService.receiveNotify(request,out);
    }
}
